package com.example.douyin.home;

import androidx.lifecycle.MutableLiveData;

import com.example.lib_base_mvvm.baseMVVM.BaseViewModel.BaseViewModel;
import com.example.lib_base_mvvm.entity.PinglunEntity;
import com.example.lib_base_mvvm.entity.ResultEntity;
import com.example.lib_base_mvvm.entity.VideoEntity;
import com.example.lib_base_mvvm.utils.ConstantsUtils;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class HomeViewModel extends BaseViewModel<HomeRepo> {
    @Override
    protected HomeRepo createRepo() {
        return new HomeRepo();
    }
    public MutableLiveData<VideoEntity> videoSuccess = new MutableLiveData<>();
    public MutableLiveData<String> videoFail = new MutableLiveData<>();

    public MutableLiveData<ResultEntity> loveSuccess = new MutableLiveData<>();
    public MutableLiveData<String> loveFail = new MutableLiveData<>();

    public MutableLiveData<ResultEntity> noloveSuccess = new MutableLiveData<>();
    public MutableLiveData<String> noloveFail = new MutableLiveData<>();

    public MutableLiveData<ResultEntity> guanzhuSuccess = new MutableLiveData<>();
    public MutableLiveData<String> guanzhuFail = new MutableLiveData<>();

    public MutableLiveData<PinglunEntity> pinglunSuccess = new MutableLiveData<>();
    public MutableLiveData<String> pinglunFail = new MutableLiveData<>();

    public MutableLiveData<PinglunEntity> sendpinglunSuccess = new MutableLiveData<>();
    public MutableLiveData<String> sendpinglunFail = new MutableLiveData<>();

    public void video(int page,int size){
        repo.video(page,size,videoSuccess,videoFail);
    }

    public void love(int videoId){
        repo.love(videoId,loveSuccess,loveFail);
    }

    public void nolove(int videoId){
        repo.nolove(videoId,noloveSuccess,noloveFail);
    }

    public void guanzhu(String name){
        Map<String,String> map = new HashMap<>();
        map.put(ConstantsUtils.PARAM_AUTHNAME,name);
        String s = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(ConstantsUtils.PARAM_TYPE_JSON),s);
        repo.guanzhu(body,guanzhuSuccess,guanzhuFail);
    }

    public void pinglun(int videoId){
        repo.pinglun(videoId,pinglunSuccess,pinglunFail);
    }

    public void sendpinglun(int videoId,String msg){
        Map<String,String> map = new HashMap<>();
        map.put(ConstantsUtils.VIDEO_URL,videoId+"");
        map.put(ConstantsUtils.PARAM_MSG,msg);
        String s = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(ConstantsUtils.PARAM_TYPE_JSON),s);
        repo.sendpinglun(body,sendpinglunSuccess,sendpinglunFail);
    }
}
